from music21 import *
import os
'''
安装 MuseScore3
下载地址：https://musescore.org/zh-hans
Lib->subprocess.py 需要修改
找到文件中的shell=False，改成shell=True
以下代码不配置会报错，须绝对路径
'''

# get environment
env = environment.Environment()
env['musicxmlPath'] = 'C:\\Program Files\\MuseScore 3\\bin\\MuseScore3.exe'
env['musescoreDirectPNGPath'] = 'C:\\Program Files\\MuseScore 3\\bin\\MuseScore3.exe'

print(env)
# check the path
print('Environment settings:')
print('musicXML:  ', env['musicxmlPath'])
print('musescore: ', env['musescoreDirectPNGPath'])

# set path if necessary
# env['musicxmlPath'] = 'path/to/your/musicXmlApplication'
# env['musescoreDirectPNGPath'] = 'path/to/your/museScore'

score = stream.Score()

def doMusic(text):
    global mid,track
    tmpmsg = {'处理结果':''}  
    if '新建乐谱' in text:
        tmpmsg['处理结果'] = '乐谱已创建'
    elif '添加音符' in text:
        tmpmsg['处理结果'] = '音符已添加'
    elif '生成音乐' in text:
        littleMelody = converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#")
        littleMelody.show('musicXML')
        tmpmsg['处理结果'] = 'midi音乐已生成'
    return tmpmsg
